﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using XMK.Tadong.Model;
using XMK.Utils;
using XMK.Tadong.DataSearch.Data;
using XMK.Framework.Model;

namespace XMK.Tadong.DataSearch.Biz
{
    public class SearchKeywordBiz
    {
        /// <summary>
        /// 查询关键词
        /// </summary>
        /// <param name="ps"></param>
        /// <returns></returns>
        public List<SearchKeywordInfo> QueryKeyword(params KeyValuePair<string, string>[] ps)
        {
            List<SearchKeywordInfo> keywordList = new List<SearchKeywordInfo>();
            try
            {
                SearchKeywordData data = new SearchKeywordData(DataSearchConfig.TadongDbProvider);
                PageInfo pageInfo = new PageInfo();
                pageInfo.PageSize = int.Parse(ps.FirstOrDefault(p => p.Key.ToLower().Equals("pagesize")).Value);
                keywordList = data.QueryKeyword(ps.FirstOrDefault(p => p.Key.ToLower().Equals("keyw")).Value, pageInfo);
            }
            catch (System.Exception ex)
            {
                LogHelper.WriteLog(LogType.Error, "[SearchKeywordBiz.QueryKeyword Exception] : " + ex.ToString());
            }
            return keywordList;
        }

        /// <summary>
        /// 存储关键词
        /// </summary>
        /// <param name="keywordInfo"></param>
        public bool AddKeyword(SearchKeywordInfo keywordInfo)
        {
            bool isSuccess = true;
            try
            {
                SearchKeywordData data = new SearchKeywordData(DataSearchConfig.TadongDbProvider);
                data.AddKeyword(keywordInfo.Keyword);
            }
            catch (System.Exception ex)
            {
                isSuccess = false;
                LogHelper.WriteLog(LogType.Error, "[SearchKeywordBiz.AddKeyword Exception] : " + ex.ToString());
            }
            return isSuccess;
        }
    }
}
